import Vue from 'vue';
import VueRouter from 'vue-router';
import { importAll } from '@/utils/util';
import hooks from './hooks';
import BasicLayout from '@/layouts/BasicLayout';
import store from '../store';

Vue.use(VueRouter);

const routeModules = importAll(require.context('./modules', true, /^(?!.*(?:index.js$)).*\.js$/), 'array');

const routes = [
  {
    path: '/home',
    component: BasicLayout,
    meta: {
      title: '',
    },
    children: [...routeModules],
  },
  {
    name: 'login',
    path: '/login',
    component: () => import('@/views/login'),
    props: route => ({
      redirectUrl: route.query.redirectUrl,
    }),

    meta: {
      title: '登录',
      hidden: true,
    },
  },
  {
    name: 'exception',
    path: '/exception',
    component: BasicLayout,
    meta: {
      hidden: true,
    },
    children: [
      {
        name: '404',
        path: '404',
        component: () => import('@/views/exception/404'),

        meta: {
          title: '404',
          hidden: true,
        },
      },
    ],
  },
  // { path: '/', redirect: store.state.user.menu[0].path || '/seePlate', meta: { hidden: true } },
  { path: '/', redirect: '/exception', meta: { hidden: true } },
  { path: '/video', component: () => import('@/views/al_productionProcess/video'), meta: { hidden: true } }, // 视频看板
  { path: '/task', component: () => import('@/views/al_productionProcess/task'), meta: { hidden: true } }, // 视频看板
  { path: '/control', component: () => import('@/views/al_productionProcess/control'), meta: { hidden: true } }, // 视频看板
  { path: '*', redirect: '/exception/404', meta: { hidden: true } }, // 404 page must be placed at the end !!!
];

const router = new VueRouter({
  routes,
});

hooks(router);

export default router;
export { routes };
